* Creating neighborhood Protest variable
insheet using "https://icr.ethz.ch/data/cshapes/Dyadic_distance_data/cshapes_2.0_dist_COW.csv", clear

drop if year<1955 | year>2010
drop if ccode1==ccode2

replace ccode1=255 if ccode1==260
replace ccode2=255 if ccode2==260
replace ccode1=315 if ccode1==316
replace ccode2=315 if ccode2==316
replace ccode1=679 if ccode1==678
replace ccode2=679 if ccode2==678

merge m:1 ccode2 year using "C:\Users\mariu\Dropbox\Secret Police Protest\Data\Replication\Source data\latentdata.dta", keepusing(mean3 mean5 mean7)

drop if _merge==2
drop _merge

sort ccode1 year ccode2

* as in Escriba-Folch, Meseguer, Wright 2018, define neighborhood as Capital Distance <=4000km
drop if capdist>4000

* Collapse mean3, mean5, and mean7 by ccode1 and year, generate averages
collapse (mean) nbr_mean3=mean3 nbr_mean5=mean5 nbr_mean7=mean7, by(ccode1 year)

rename ccode1 ccode

save "C:\Users\mariu\Dropbox\Secret Police Protest\Data\Replication\Source data\Temp\neighbor_protest.dta", replace